package cn.edu.scau.cmi.chenruilin.abstractFactory.factory;


import cn.edu.scau.cmi.chenruilin.abstractFactory.domainAbstractClass.ConsumerElectronicsDevice;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;

public class Controller {

    @FXML
    private Label output;

    @FXML
    private ChoiceBox<Object> meatType;

    @FXML
    private ChoiceBox<Object> company;

    @FXML
    private Button shopping;

    @FXML
    void buyMeat() {
    	try {
    		String brand = (String)company.getValue();
        	String meat = (String)meatType.getValue();
        	
        	AbstractFactory factory = null;
        	switch(brand){
        	case"温氏集团": factory=AbstractFactory.getFactory("wens");break;
        	case"天邦集团": factory=AbstractFactory.getFactory("tianbang");break;
        	case"傲农集团": factory=AbstractFactory.getFactory("aonong");break;
        	};
        	ConsumerElectronicsDevice election = null;
        	switch(meat){
        	case"牛肉": election=factory.createBeef();break;
        	case"猪肉": election=factory.createPork();break;
        	case"鸡肉": election=factory.createChicken();break;
        	};
        	String out = election.buy();
        	output.setText(out);
    	}
    	catch(Exception e) {
    		output.setText("请选择要购买的商品品牌和商品类型！");
    		
    	}
    	
    }
    
    
    @FXML
    void initialize() {
    	company.setItems(FXCollections.observableArrayList(
    			"温氏集团", new Separator(), "天邦集团", new Separator(), "傲农集团")
    		);
    	meatType.setItems(FXCollections.observableArrayList(
    			"牛肉", new Separator(), "猪肉", new Separator(), "鸡肉")
    			);

    }
}

